var win = document.createElement("div");
win.style.position = 'fixed';
win.style.zIndex=999999;
win.style.bottom=0
win.style.right=0;
win.style.backgroundColor='white';
win.style.border = 'solid';
win.style.borderWidth = '1px';
win.style.borderColor = 'rgb(184, 201, 226)';
win.style.boxShadow = '-8px -8px 10px rgba(0, 0, 0, 0.5)';
win.style.display='none';

document.body.appendChild(win);

var baiduURL = 'http://wbk.baidu.com/search?word=';
var wikiURL = 'http://zh.m.wikipedia.org/wiki/';
var youdaoDictURL = 'http://dict.youdao.com/m/search?q=';

document.onmouseup=function(e){
	var txt = getSelected();
	console.debug(txt);
	if(txt){
		win.innerHTML = '<iframe id="w" style="border:none;" src='+youdaoDictURL+txt+' width="300" height="400" />';
		win.style.display='block';	
	}else{
		win.style.display='none';
	}
};

function getSelected() {
    var text = "";
    var sel = window.getSelection();
	var container = document.createElement("div");
    for (var i = 0, len = sel.rangeCount; i < len; ++i) {
        container.appendChild(sel.getRangeAt(i).cloneContents());
    }
    text = container.innerText;
    return text;
}